<?php 
	
    $conn = oci_connect("hospital", "hospital", "//localhost/XE"); 
    $pull = oci_parse($conn, "select * from staff where stf_id = $_GET[col]");
    oci_execute($pull);
    $job = oci_fetch_array($pull,OCI_RETURN_LOBS );
    
    //echo $_POST['job_type'];
    $fdoc = oci_parse($conn, "select * from DOCTORS where st_id = $_GET[col]");
    oci_execute($fdoc);
    $type = oci_fetch_array($fdoc,OCI_RETURN_LOBS );
            
    if($_POST['job_type'] == 'DOC'){
            $name = 'DOCTORS';
    }else if($_POST['job_type'] == 'NUR'){
            $name = 'NURSES';
    }else if($_POST['job_type'] == 'EXE'){
            $name = 'EXECUTIVES';
    }else if($_POST['job_type'] == 'FIN'){
            $name = 'FINANCES';
    }
    
    if($type['DOCTORTYPE'] == 'ANE'){
        $doc_name = 'ANESTHESISTS';
    }else if($type['DOCTORTYPE']== 'SUR'){
        $doc_name = 'SURGEONS';
    }else if($type['DOCTORTYPE'] == 'GEN'){
        $doc_name = 'GENERAL_PRACTICE';
    }
    if($_POST['job_type'] == 'DOC'){
        if($_POST['doc_type'] == 'ANE'){
           $fdoc_name = 'ANESTHESISTS';
        }else if($_POST['doc_type'] == 'SUR'){
            $fdoc_name = 'SURGEONS';
        }else if($_POST['doc_type'] == 'GEN'){
            $fdoc_name = 'GENERAL_PRACTICE';
        }
    }
  //  echo $name;
    
    if($job['JOB_TYPE'] == $_POST['job_type']){             //JOB_TYPE IS NOT CHANGE
         $ss = "UPDATE STAFF SET STF_ID = '$_POST[stf_id]', F_NAME = '$_POST[f_name]', L_NAME = '$_POST[l_name]', 
                JOB_TYPE = '$_POST[job_type]',SALARY ='$_POST[salary]', START_CONTACT = '$_POST[startcontract]', 
                END_CONTACT ='$_POST[endcontract]'
                WHERE STF_ID = '$_GET[col]' ";
		
	$update= oci_parse($conn,$ss);
	oci_execute($update);
        
        if($_POST['job_type'] == 'DOC'){
            $que = "UPDATE DOCTORS SET ST_ID = '$_POST[stf_id]', DOC_TYPE = '$_POST[doc_type]'
                    WHERE ST_ID = '$_GET[col]' ";     
            
            $que_d = "UPDATE $doc_name SET STD_ID = '$_POST[stf_id]' WHERE STD_ID = '$_GET[col]'";
            $update_doctype = oci_parse($conn, $que_d);
            oci_execute($update_doctype);
            
        }else{
            $que = "UPDATE $name SET ST_ID = '$_POST[stf_id]' 
                    WHERE ST_ID = '$_GET[col]' ";
        } 
	$updater= oci_parse($conn,$que);
	oci_execute($updater);
        
        
    }else{      //CHANGE JOB_TYPE
        if($job['JOB_TYPE'] == 'DOC'){
            $fname = 'DOCTORS';
            
            $dell = oci_parse($conn, "delete from $doc_name where std_id = '$_GET[col]'");
            oci_execute($dell);
            
        }else if($job['JOB_TYPE'] == 'NUR'){
            $fname = 'NURSES';
        }else if($job['JOB_TYPE'] == 'EXE'){
            $fname = 'EXECUTIVES';
        }else if($job['JOB_TYPE'] == 'FIN'){
            $fname = 'FINANCES';
        }
        
        $deleted = oci_parse($conn, "delete from $fname where ST_ID = '$_GET[col]'");
        oci_execute($deleted);
            
        $ss = "UPDATE STAFF SET STF_ID = '$_POST[stf_id]', F_NAME = '$_POST[f_name]', L_NAME = '$_POST[l_name]', JOB_TYPE = '$_POST[job_type]',
		SALARY ='$_POST[salary]', START_CONTACT = '$_POST[startcontract]', END_CONTACT ='$_POST[endcontract]'
	    WHERE STF_ID = '$_GET[col]' ";
		
	$update= oci_parse($conn,$ss);
	oci_execute($update);
        
        if($_POST['job_type'] == 'DOC'){
            $query = "INSERT INTO DOCTORS VALUES ('$_POST[stf_id]','$_POST[doc_type]')";
            $query_d = oci_parse($conn,"INSERT INTO $fdoc_name VALUES ('$_POST[stf_id]')");
            $addnew = oci_parse($conn, $query);
            oci_execute($addnew);
            oci_execute($query_d);
        }else{
            $query = "INSERT INTO $name VALUES ('$_POST[stf_id]')";
            $addnew = oci_parse($conn, $query);
            oci_execute($addnew);
        }
        
        
    }
    
	
 ?>
 
<html>
<head><meta http-equiv="refresh" content="1; URL=main.php"></head>
<BODY bgcolor = "#ffffff">
 <font color="#ffffff" size="20">Redirecting ...</font>
 </body>
 </html>
